/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import common.Message;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Danny
 */
class MessagesTableModel extends AbstractTableModel {

    Message[] messages;

    MessagesTableModel(Message[] messagesFromServer) {
        this.messages = messagesFromServer;
    }

    public void setMessages(Message[] messages) {
        this.messages = messages;
    }

    public MessagesTableModel() {
        this.messages = new Message[0];
    }

    public int getRowCount() {
        return messages.length;
    }

    public int getColumnCount() {
        return 3;
    }

    @Override
    public String getColumnName(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return "User pseudonym";
            case 1:
                return "Message";
            case 2:
                return "Date";
        }
        return "MessagesTableModel- getColumnName";
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return messages[rowIndex].getClientID();
            case 1:
                return messages[rowIndex].getContentString();
            case 2:
                return messages[rowIndex].getDate();
        }
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
